package com.hava.spring_data;

import com.hava.spring_data.entity.BigUser;
import com.hava.spring_data.entity.User;
import com.hava.spring_data.repository.MyBatisDao;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by yanfa on 2016/10/26.
 */
public class MyBatisSpringMain {

    public static void main(String [] args){
        ApplicationContext context = new ClassPathXmlApplicationContext("mybatis-context.xml");

        MyBatisDao myBatisDao = context.getBean("myBatisDao",MyBatisDao.class);

        for(User user : myBatisDao.findAll())
            System.out.println(user.getFirst_name() + " " + user.getLast_name());

        User user = myBatisDao.findOne("Zhan");
        System.out.println(user.getId() + ":" + user.getFirst_name() + " " + user.getLast_name());

        for(BigUser bigUser : myBatisDao.getUserList())
            System.out.println(bigUser.getFirstName() + " " + bigUser.getLastName());

        ((ConfigurableApplicationContext) context).close();
    }
}
